package com.study.designPattern.singleton;

/**
 * Created by HBZ on 2017/5/16.
 * double-checked locking设计实现单例模式
 */
public class SingletonClass1 {
    private static SingletonClass1 instance = null;

    public static SingletonClass1 getInstance() {
        if (instance == null) {
            synchronized (SingletonClass1.class) {
                if (instance == null) {
                    instance = new SingletonClass1();
                }
            }
        }
        return instance;
    }
   /*如果存在很多次getInstance()的调用,性能会很低
  /*  public synchronized static com.study.Singleton.SingletonClass1 getInstance() {
        if(instance == null) {
            instance = new com.study.Singleton.SingletonClass1();
        }
        return instance;
    }*/

    private SingletonClass1() {

    }

}
